package com.rs.game.player.dialogues.impl;

import com.rs.game.WorldTile;
import com.rs.game.player.Skills;
import com.rs.game.player.content.dungeoneering.Dungeon;
import com.rs.game.player.content.dungeoneering.DungeonConstants;
import com.rs.game.player.content.dungeoneering.DungeonManager;
import com.rs.game.player.content.dungeoneering.DungeonPartyManager;
import com.rs.game.player.content.dungeoneering.DungeonPartyPlayer;
import com.rs.game.player.dialogues.Dialogue;

public final class DungeonFinish extends Dialogue {

	int npcId;


	@Override
	public void start() {
		sendDialogue("You have unlocked the door, you may step across.");
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (stage == -1) {
			sendOptionsDialogue("Leave the dungeon and return to the surface?", "Yes.", "No.");
			stage = 0;
		} else if (stage == 0) {
			if (componentId == OPTION_1) {
				int deaths = (1 + DungeonPartyPlayer.getDeaths());
				int dunglevel = player.getSkills().getLevel(Skills.DUNGEONEERING);
				int xpReward = 16 * (((dunglevel / deaths)));
				int size = (1 + DungeonPartyManager.size);
				int floorcompletion = (DungeonManager.getRoomsOpened() / Dungeon.getRoomCount());
				int realreward = (xpReward * 90);
				int tokenReward = (realreward / 10);
				player.setDungtokens(player.getDungtokens() + tokenReward);
				player.getSkills().addXp(Skills.DUNGEONEERING, xpReward);
				player.getPackets().sendGameMessage("You've opened "+DungeonManager.getRoomsOpened()+ " rooms of "+Dungeon.getRoomCount()+" rooms.");
				player.getPackets().sendGameMessage("You exit the dungeon...");
				player.getPackets().sendGameMessage("and gain "+ realreward + " dungeoneering XP and " 
						+ tokenReward + " tokens for completing the floor!");
				player.getPackets().sendGameMessage("You currently have " + player.getDungtokens() + " dungeoneering tokens.");
				player.getControlerManager().getControler().removeControler();
				player.getControlerManager().forceStop();
				player.getPackets().closeInterface(player.getInterfaceManager().hasRezizableScreen() ? 34 : 8);
				player.useStairs(-1, new WorldTile(DungeonConstants.OUTSIDE, 2), 0, 1);
				player.getCombatDefinitions().removeDungeonneringBook();
				player.setForceMultiArea(false);
				player.getControlerManager().removeControlerWithoutCheck();
				player.getInterfaceManager().removeOverlay(false);
				end();
			} else if (componentId == OPTION_2) {
				end();
			}
		}
	}

	@Override
	public void finish() {

	}

}